<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @author Anh Nguyen <duyanhnguyen@vccorp.vn>
 * @copyright 2012
 */

class Category_model extends CI_Model
{

    public function getCategoryInfo($catId, $langCode)
    {
        $return = array();
        $this->db->select("id, parent_id, name_$langCode as 'name', href");
        $this->db->from('category');
        $this->db->where(array(
            'id'    =>  $catId,
            'status'    =>  '1'
        ));
        $rs = $this->db->get();
        if ($rs->num_rows() > 0) {
            $return = $rs->result_array();
            $rs->free_result();
            return $return;
        } else {
            $rs->free_result();
            return false;
        }
    }
    
    public function getParentCategory($langCode,$status = true)
    {
        $return = array();
        $this->db->select("id, parent_id, name_$langCode as 'name', href");
        $this->db->from('category');
        if ($status) {
            $this->db->where(array(
                'parent_id' => '0',
                'status' => '1'
            ));
        } else {
            $this->db->where(array(
                'parent_id' => '0'
            ));
        }
        $rs = $this->db->get();
        $return = $rs->result_array();
        $rs->free_result();
        return $return;
    }

    public function getChildrenCategory($parentId,$langCode,$status = true)
    {
        $return = array();
        $this->db->select("id, parent_id, name_$langCode as 'name', href");
        $this->db->from('category');
        if ($status) {
            $this->db->where(array(
                'parent_id' => $parentId,
                'status' => '1'
            ));
        } else {
            $this->db->where(array(
                'parent_id' => $parentId
            ));
        }
        $rs = $this->db->get();
        if ($rs->num_rows() > 0) {
            $return = $rs->result_array();
            $rs->free_result();
            return $return;
        } else {
            $rs->free_result();
            return false;
        }
    }

}

?>
